package com.shijie.handle.exception;

import com.shijie.exception.OtherException;
import com.shijie.exception.SubmitException;
import com.shijie.result.SjResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SubmitException.class)
    public SjResult<Void> handleSubmitException(SubmitException exception) {
        log.error(exception.toString());

        return SjResult.error(exception.getMessage());
    }

    @ExceptionHandler(OtherException.class)
    public /*SjResult<Void>*/ void handleOtherException(OtherException exception) {
        log.error(exception.toString());

//        return SjResult.error(exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public void handleException(Exception exception) {
        log.error(exception.toString());
    }

}
